import {
    ref
} from "vue";

export const prientShow = ref(false);

import predictionOrderDetail from '@/api/prediction/predictionOrderDetail'

// 打印表格数据
export let p_data = null;
// 获取打印表单数据
export const getPrientData = (crudRef, id) => {
    predictionOrderDetail.getList({
        page:1,
        pageSize:1000,
        order_id: id,
        order: 'created_at',
        orderType: 'desc'
    }).then(res => {
        let _data = res.data.items
        console.log('dayin:',_data)
        if(_data.length != 0 && _data[0].transport_type == 2){
            _data.map((v,i)=>{
                v.car_no = v.prediction.car_no - 0
            })
            _data =  _data.sort(sortBy("car_no",false))
        }
        _data.map((v,i)=>{
            v.dept_name = v.dept.name
            
        })
        p_data = _data.filter(item=>item.pick_weight_yu);
        prientShow.value = true;
    })
};
const sortBy = (attr,rev)=>{
    //第二个参数没有传递 默认升序排列
      if(rev ==  undefined){
          rev = 1;
      }else{
          rev = (rev) ? 1 : -1;
      }
      
      return function(a,b){
          a = a[attr];
          b = b[attr];
          if(a < b){
              return rev * -1;
          }
          if(a > b){
              return rev * 1;
          }
          return 0;
      }
  }

export const cancelPrientPopup = (e) => {
    prientShow.value = false;
}